﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HdRSpielbox.muehle
{
    public partial class Muehle1 : Form
    {
        #region Variablendeklaration
        private Muehle m;
        #endregion
        #region Konstruktor
        public Muehle1(Muehle m)
        {
            this.m = m;
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true); 
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }
        #endregion
        #region On Paint Overrides
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            Graphics g = e.Graphics;
            Brush b = new SolidBrush(Color.Gold);
            foreach (Linie3 l in m.Linien)
            {
                l.Draw(g, b);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Font f = new Font("Arial",17,FontStyle.Bold);
            if (m.Phase < 3)
            {
                if (!m.Muehle_gefunden)
                {
                    g.DrawString(m.Active_player.name + " ist am Zug ", f, new SolidBrush(Color.Black), 100, 0);
                }
                else
                {
                    g.DrawString(m.Active_player.name + " hat eine Mühle", f, new SolidBrush(Color.Black), 100, 0);
                }
            }
            else
            {
                g.DrawString(m.Winner.name + " hat Gewonnen !", f, new SolidBrush(Color.Black), 100, 0);
                Btn_NeuStart.Visible = true;
            }
            foreach (Knoepf  k in m.Knoepfe)
            {
                k.Draw(g);
            }
        }
        #endregion
        #region Eventhandlers
        private void Muehle1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                m.Draging_point.p.X = e.Location.X;
                m.Draging_point.p.Y = e.Location.Y;
                this.Refresh();
            }
        }
        private void Muehle1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                m.Draging_point.p.X = e.Location.X;
                m.Draging_point.p.Y = e.Location.Y;
                this.Refresh();
            }
        }
        private void Muehle1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                m.Draging_point.p.X = e.Location.X;
                m.Draging_point.p.Y = e.Location.Y;
                m.Mouse_down(sender, e);
            }
        }
        private void Muehle1_MouseUp(object sender, MouseEventArgs e)
        {
            m.Mouse_up(sender, e);
        }
        private void Btn_NeuStart_Click(object sender, EventArgs e)
        {
            Btn_NeuStart.Visible = false;
            m.Init();
            m.Start();

        }
        #endregion

        private void btnKI_Next_Click(object sender, EventArgs e)
        {
            m.ki_next();
        }

        private void Muehle1_Load(object sender, EventArgs e)
        {

        }

        private void Muehle1_FormClosing(object sender, FormClosingEventArgs e)
        {

        }
    }
}
